package com.le.dub.service.thread;

import cn.hutool.core.util.ObjectUtil;
import com.le.dub.conf.RedisKey;
import com.le.dub.conf.ThreadPoolConfig;
import com.le.dub.service.IAppVoiceService;
import com.le.dub.service.IDubRoleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class CloneThread implements Runnable{
    @Resource
    private RedisTemplate template;
    @Resource
    private IDubRoleService roleService;
    @Resource
    private ThreadPoolConfig threadPoolConfig;
    @Override
    public void run() {
        while (true){
            if (template.hasKey(RedisKey.cloneList)) {
                Object recordIdStr= template.opsForList().leftPop(RedisKey.cloneList);
                if(ObjectUtil.isNotNull(recordIdStr)){
                    Long recordId= Long.valueOf(recordIdStr.toString());
                    log.info("开始执行任务"+recordId);

                    threadPoolConfig.threadPoolTaskExecutor().execute(new Runnable() {
                        @Override
                        public void run() {
                            roleService.executeClone(recordId);

                        }
                    });
                }
            }

        }

    }
}
